import React, { useState } from 'react'
import { useHistory } from 'react-router-dom'
import { putAccSupportAddSupport } from '../../../../financialApi'
import moment from 'moment'
import { Button, Form, Input, InputNumber, message, Radio } from 'antd'

const { TextArea } = Input;

/**
 * @description: 财务--服务申请表
 * @author: xiaoxujs
 * @update: xiaoxujs（2021-07-08）
 */

const Serve = () => {
    const history = useHistory()
    const [buttonLoading, setButtonLoading] = useState(false)
    const onFinish = (values) => {
        values.startTime = moment(values.startTime).format('YYYY-MM-DD')
        values.endTime = moment(values.endTime).format('YYYY-MM-DD')
        ; (async () => {
            setButtonLoading(true)
            const { code, msg } = await putAccSupportAddSupport(values)
            if (code === '20000') {
                message.success('提交成功')
                setButtonLoading(false)
                history.go('-1')
            } else {
                setButtonLoading(false)
                message.error(msg)
            }
        })()
    };
    return <Form
        labelCol={{ span: 3 }}
        wrapperCol={{ span: 16 }}
        onFinish={onFinish}
    >
        <Form.Item
            label="发票"
            name="isTicket"
            rules={[{ required: true, message: '请选择是否有发票!' }]}
        >
            <Radio.Group>
                <Radio value={0}>有票</Radio>
                <Radio value={1}>无票</Radio>
            </Radio.Group>
        </Form.Item>
        <Form.Item
            label="出差事由"
            name="matter"
            rules={[{ required: true, message: '请输入出差事由!' }]}
        >
            <TextArea />
        </Form.Item>
        <Form.Item
            label="借款金额（元）"
            name="money"
            rules={[{ required: true, message: '请输入借款金额!' }]}
        >
            <InputNumber />
        </Form.Item>

        <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
            <Button type="primary" htmlType="submit" loading={buttonLoading}>
                提交申请
            </Button>
        </Form.Item>
    </Form>
}

export default Serve